package com.xindz.cn.mvptest.components.product.data;

import com.avos.avoscloud.AVClassName;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVFile;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.FindCallback;
import com.avos.avoscloud.SaveCallback;

import java.util.HashMap;

/**
 * @name MvpTest
 * @class name：com.xindz.cn.mvptest.components.product.data
 * @describe 自定义Bean继承AVObject 添加注解@AVClassName("Product"),并且在App中进行注册
 * @anthor XINDZ
 * @time 2017/10/30 17:48
 * @change
 * @chang time
 * @class describe
 */
@AVClassName("Product")
public class ProductBean extends AVObject {
    private String description;
    private String title;
    private String image;
    private String xindz;
    private int price;
    private AVFile tstFile;

    public AVFile getTstFile() {
        return this.getAVFile("tstFile");
    }

    public void setTstFile(AVFile tstFile) {
        this.put("tstFile", tstFile);
    }

    private AttachProductBean attachProductBean;

    public AttachProductBean getAttachProductBean() {
        try {
            return this.getAVObject("AttachProduct", AttachProductBean.class);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public void setAttachProductBean(AttachProductBean attachProductBean) {
        this.put("AttachProduct", attachProductBean);
    }

    public String getDescription() {
        return this.getString("description");
    }

    public void setDescription(String description) {
        this.put("description", description);
    }

    public String getTitle() {
        return this.getString("title");
    }

    public void setTitle(String title) {
        this.put("title", title);
    }

    public String getImage() {
        String imageUrl = "";
        AVFile imageFile = this.getAVFile("image");
        if (imageFile != null) imageUrl = imageFile.getUrl();
        return imageUrl;
    }

    public void setImage(String imageName, String imageUrl) {
        this.put("image", new AVFile(imageName, imageUrl, new HashMap<String, Object>()));
    }

    public String getXindz() {
        return this.getString("xindz");
    }

    public void setXindz(String xindz) {
        this.put("xindz", xindz);
    }

    public int getPrice() {
        return this.getInt("price");
    }

    public void setPrice(int price) {
        this.put("price", price);
    }


    public void save(){
        ProductBean productBean =new ProductBean();
        productBean.saveInBackground(new SaveCallback() {
            @Override
            public void done(AVException e) {

            }
        });

    }
}
